package hz.mobileproject.pda.utils;

import android.os.Environment;

import java.io.File;

public class FileUtils {

	private static final String SD_PATH = Environment.getExternalStorageDirectory().getPath();
	private static final String DATA_PATH = Environment.getDataDirectory().getPath();
	private static final String SD_STATE = Environment.getExternalStorageState();
	public static final String MAIN_NAME = "hzJWT";

	public static String getAppPath(String name) {
		StringBuilder sb = new StringBuilder();
		if (SD_STATE.equals(
				android.os.Environment.MEDIA_MOUNTED)) {
			sb.append(SD_PATH);
		} else {
			sb.append(DATA_PATH);
		}
		sb.append(File.separator);
		sb.append(MAIN_NAME);
		sb.append(File.separator);
		sb.append(name);
		sb.append(File.separator);

		File file = new File(sb.toString());
		if(!file.exists()){
			file.mkdirs();
		}
		return sb.toString();
	}

	/**
	 * SD卡是否可用
	 */
	public static boolean isSDCardAvailable() {
		return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
	}

	public static String recAudioPath(String file) {
		return new File(Environment.getExternalStorageDirectory(), file).getAbsolutePath();
	}

	public static File recAudioDir(String path) {
		File file = new File(path);
		if (!file.exists()) {
			file.mkdirs();
		}
		return file;
	}
}
